import requests as rq

#  r 的 Response 对象
# r = rq.get('https://api.github.com/events')

# print(r.text) # json 字符串
# print(r.encoding) # utf-8
# r.encoding = 'gbk'
# print(r.text)
# print(r.encoding)
# print(r.content) # 二进制

# 内置了json解析器
# js = r.json()
# print(js)

# 请求返回的状态码
# code = r.status_code
# print(code)

# print(r.raw)
# rp = r.raw
# print(rp.read(100))

# 响应头
# print(r.headers)

# r = rq.post('http://httpbin.org/post', data = {'key':'value'})
# print(r.text)

baseurl = 'http://localhost:8001/LIMS-Server/MPLM_Service_Gateway/'
# baseurl = 'https://limssit.midea.com/LIMS-Server/MPLM_Service_Gateway/'


def getToken():
    url = baseurl+'TokenGenerator/getToken'
    headers = {
        '__TokenAuthorization_UserName_': 'ex_cuiml1',
        '__TokenAuthorization_Function_': 'getTestForm'
    }
    response = rq.post(url, headers=headers)
    # print(response.text)
    # print(response.json())
    retjson = response.json()
    # print(retjson['token'])
    return retjson['token']


def postForm():
    url = baseurl+'raclimsRestfulController/getTestForm'
    token = getToken()
    headers = {
        '__TokenAuthorization_UserName_': 'ex_cuiml1',
        '__TokenAuthorization_Function_': 'getTestForm',
        '__TokenAuthorization_UID_': getToken()
    }
    data = {
        'EntrustmentOrder': 'ST2023040019'
    }
    response = rq.post(url=url, headers=headers, data=data)
    return response.json()


if __name__ == '__main__':
    # url1 = 'http://localhost:8080/user/findAll'
    # r = rq.get(url1)
    # # print(r.content)
    # print(r.text)
    # token = getToken()
    # print(token)

    # json = postForm()
    # print(json)

    print(rq.__doc__)